<blockquote class="layui-elem-quote">
    <div class="layui-inline">
        <i class="layui-icon layui-icon-list layui-head-icon"></i>
        <span class="layui-font-16 layui-font-green">商品分类管理</span>
    </div>
    <div class="layui-pull-right">
        <a class="layui-btn layui-btn-primary layui-border-green"
           data-url="{:url('/store/goods/category/create')}"
           data-title="添加商品分类"
           data-w="800px"
           data-h="700px"
           id="add">添加商品分类</a>
    </div>
</blockquote>
<div class="layui-card">
    <div class="layui-card-body">
        <fieldset class="layui-elem-field">
            <legend>条件搜索</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane" action="{:url('/store/goods/category')}" method="GET">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">分类名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" placeholder="请输入分类名称" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <form class="layui-form">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>分类名称</th>
                    <th>状态</th>
                    <th>首页(显示/隐藏)</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                {foreach $list as $vo}
                <tr>
                    <td>{$vo.id}</td>
                    <td>{$vo.name}</td>
                    <td>
                        {empty name='$vo.status'}
                        <span class="layui-font-red">禁用</span>
                        {else/}
                        <span class="layui-font-green">启用</span>
                        {/empty}
                    </td>
                    <td>
                        {empty name='$vo.is_home'}
                        <span class="layui-font-red">隐藏</span>
                        {else/}
                        <span class="layui-font-green">显示</span>
                        {/empty}
                    </td>
                    <td>{$vo.create_time}</td>
                    <td>{$vo.update_time}</td>
                    <td>
                        {empty name='$vo.status'}
                        <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-green switch"
                           data-url="{:url('/store/goods/category/switch')}"
                           data-status="1"
                           data-id="{$vo.id}">启用</a>
                        {else/}
                        <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-red switch"
                           data-url="{:url('/store/goods/category/switch')}" data-status="0" data-id="{$vo.id}">禁用</a>
                        {/empty}
                        {empty name='$vo.parent_id'}
                            {empty name='$vo.is_home'}
                            <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-green is_home"
                               data-home="1"
                               data-id="{$vo.id}">首页显示</a>
                            {else/}
                            <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-red is_home"
                               data-home="0" data-id="{$vo.id}">首页隐藏</a>
                            {/empty}
                        {/empty}
                        <a class="layui-btn layui-btn-sm edit"
                           data-url="{:url('/store/goods/category/edit',['id'=> $vo.id])}"
                           data-title="编辑分类"
                           data-w="800px"
                           data-h="700px">编辑</a>
                        <a class="layui-btn layui-btn-sm layui-btn-warm copy"
                           data-url="{:url('/store/goods/category/child',['id' => $vo.id])}"
                           data-title="添加子分类"
                           data-w="700px"
                           data-h="800px"
                        >添加子分类</a>
                        <a class="layui-btn layui-btn-sm layui-btn-danger del"
                           data-url="{:url('/store/goods/category/delete',['id'=> $vo.id])}">删除</a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </form>
    </div>
</div>
<script>
    $('.is_home').click(function (){
        let id = $(this).attr('data-id');
        let is_home = $(this).attr('data-home')
        layer.confirm('您确定要在首页显示吗？', {
            title:['温馨提示'],
            btn: ['确定','取消']
        }, function(){
            $.post('/store/goods/category/home',{id:id,is_home:is_home},function(res){
                if(res.code == 1){
                    layer.msg(res.msg,{icon:1});
                    parent.$.pjax.reload('#main',{fragment: '#main'});
                    return false;
                }
                layer.msg(res.msg,{icon:2});
            });
        });
    });
</script>